package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import com.aliyuncs.exceptions.ClientException;
import com.ruoyi.system.domain.GwNoticeStaff;
import com.ruoyi.system.service.IGwNoticeStaffService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.GwNotice;
import com.ruoyi.system.service.IGwNoticeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 通知公告Controller
 *
 * @author ruoyi
 * @date 2025-04-29
 */
@Api(description = "通知公告")
@RestController
@RequestMapping("/system/gwnotice")
public class GwNoticeController extends BaseController {

    @Autowired
    private IGwNoticeService gwNoticeService;
    @Autowired
    private IGwNoticeStaffService gwNoticeStaffService;

    /**
     * 查询通知公告列表
     */
    @ApiOperation("查询通知公告列表")
//    @PreAuthorize("@ss.hasPermi('system:gwnotice:list')")
    @GetMapping("/list")
    public TableDataInfo list(GwNotice gwNotice) {
        startPage();
        List<GwNotice> list = gwNoticeService.selectGwNoticeList(gwNotice);
        return getDataTable(list);
    }

    /**
     * 导出通知公告列表
     */
//    @PreAuthorize("@ss.hasPermi('system:gwnotice:export')")
    @Log(title = "通知公告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GwNotice gwNotice) {
        List<GwNotice> list = gwNoticeService.selectGwNoticeList(gwNotice);
        ExcelUtil<GwNotice> util = new ExcelUtil<GwNotice>(GwNotice.class);
        util.exportExcel(response, list, "通知公告数据");
    }

    /**
     * 获取通知公告详细信息
     */
    @ApiOperation("获取通知公告详细信息")
//    @PreAuthorize("@ss.hasPermi('system:gwnotice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(gwNoticeService.selectGwNoticeById(id));
    }

    /**
     * 获取通知公告详细信息
     */
    @ApiOperation("获取通知公告详细信息")
//    @PreAuthorize("@ss.hasPermi('system:gwnotice:query')")
    @GetMapping(value = "/query/{id}")
    public AjaxResult queryInfo(@PathVariable("id") String id) {
        return success(gwNoticeService.selectGwNoticeById(id));
    }

    /**
     * 新增通知公告
     */
    @ApiOperation("新增通知公告")
//    @PreAuthorize("@ss.hasPermi('system:gwnotice:add')")
    @Log(title = "通知公告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody GwNotice gwNotice) throws ClientException, WxErrorException {
        return toAjax(gwNoticeService.insertGwNotice(gwNotice));
    }

    @ApiOperation("设置已读")
    @PostMapping("/setRead")
    public AjaxResult setRead(@RequestBody GwNotice gwNotice){
        return toAjax(gwNoticeService.setRead(gwNotice));
    }

    @ApiOperation("新增通知员工")
//    @PreAuthorize("@ss.hasPermi('system:gwnotice:add')")
    @PostMapping("/addStaff")
    public AjaxResult addStaff(@RequestBody GwNotice gwNotice) throws ClientException, WxErrorException {
        return toAjax(gwNoticeService.addStaff(gwNotice));
    }

    @ApiOperation("获取员工已读未读列表")
//    @PreAuthorize("@ss.hasPermi('system:gwnotice:list')")
    @PostMapping("/getStaffReadList")
    public AjaxResult getStaffReadList(@RequestBody GwNoticeStaff gwNoticeStaff){
        List<GwNoticeStaff> gwNoticeStaffs = gwNoticeStaffService.selectGwNoticeStaffList(gwNoticeStaff);
        return AjaxResult.success(gwNoticeStaffs);
    }

    /**
     * 修改通知公告
     */
    @ApiOperation("修改通知公告")
//    @PreAuthorize("@ss.hasPermi('system:gwnotice:edit')")
    @Log(title = "通知公告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GwNotice gwNotice) {
        return toAjax(gwNoticeService.updateGwNotice(gwNotice));
    }

    /**
     * 删除通知公告
     */
    @ApiOperation("删除通知公告")
//    @PreAuthorize("@ss.hasPermi('system:gwnotice:remove')")
    @Log(title = "通知公告", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(gwNoticeService.deleteGwNoticeByIds(ids));
    }
}
